package com.april.dcds;

/**
 * @author April
 * 链表 简单插入与反转
 */
public class LinkList<E> {

    public void setNode(LinkNode<E> node) {
        this.node = node;
    }

    private LinkNode<E> node;

    @Override
    public String toString() {
        return "LinkList{" +
                "node=" + node +
                '}';
    }

    public void add(E e){
        if(this.node==null){
            this.node=new LinkNode<>();
            this.node.value=e;
        }else {
            LinkNode<E> node1=new LinkNode<E>();
            node1.value=e;
            node1.next=this.node;
            this.node=node1;
        }
    }
    public void reverseLink(){
        if(this.node==null||this.node.next==null){
            return ;
        }
        LinkNode p1=this.node;
        LinkNode p2=this.node.next;
        LinkNode p3=null;
        while(p2!=null){
            p3=p2.next;
            p2.next=p1;
            p1=p2;
            p2=p3;
        }
        this.node.next=null;
        this.node=p1;
    }

}
